import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {Observable} from "rxjs/Observable";
import "rxjs/add/observable/of";
import {PageParamsModel} from "../../../model/common/page-params.model";

@Injectable()
export class ClientVipProvider {
    clientsDetail;

    prePath: string;

    constructor(public http: HttpClient) {
        this.prePath = 'party/v1';
    }

    /**
     * 获取vip客户列表
     * @returns {any}
     */
    getVipList(notLoading = 0, pageModel: PageParamsModel): Observable<any> {
        const p = `vipClient`;
        const url = `/${this.prePath}/${p}`;
        return this.http.get(url, {
            params: {
                'not-loading': '' + notLoading,
                pageNum: '' + pageModel.pageNum,
                pageSize: '' + pageModel.pageSize,
                orderType:pageModel.orderType?pageModel.orderType:'',
                keyword: pageModel.condition.keyword?pageModel.condition.keyword:''
            }
        });

    }


    /**
     * 过滤为空的电话号码
     * @param clientList
     */
    checkMobileNull(clientList){
        clientList.forEach(client => {
            const mobileList = [];
            if(client.mobilePhone && client.mobilePhone.length){
                client.mobilePhone.forEach(mobile => {
                    if(mobile && mobile.mobile){
                        mobileList.push({
                            id:mobile.id,
                            mobile:mobile.mobile
                        });
                    }
                });
            }
            client.mobilePhone = mobileList;
        });
        return clientList;
    }

    public vw(v: number) {
        const w = window['innerWidth'];
        return Number((v * w / 100).toFixed(5));
    }
}
